﻿#include "cmdbox.h"
#include "ui_cmdbox.h"

CommandBox::CommandBox(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::CommandBox)
{
    ui->setupUi(this);
}

CommandBox::~CommandBox()
{
    delete ui;
}

Command CommandBox::cmdAnalyze(const QString &cmdStr)
{
    Command cmd;

    if(cmdStr == "#torus")
        cmd= torus_test;
    else if(cmdStr == "#pop")
        cmd= pop_test;
    else if(cmdStr == "#bell")
        cmd= bell_test;
    else if(cmdStr == "#re_props")
        cmd= re_props;
    else if(cmdStr == "#re_cmd")
        cmd=re_cmd;
    else if(cmdStr == "#re_location")
        cmd=re_location;
    else if(cmdStr == "#re_tool")
        cmd=re_tool;
    else if(cmdStr =="#re_group")
        cmd=re_group;
    else
    {
        cmd= cmd_search;
        searchStr=SEARCH + cmdStr;
        QDesktopServices::openUrl(QUrl(searchStr));
    }
    return cmd;
}

void CommandBox::on_btn_go_clicked()
{
    cmdStr=ui->in_cmd->text().trimmed();
    if(!cmdStr.isEmpty())
        emit sendCmd(cmdAnalyze(cmdStr));
}
